package com.relevandopeligros.activities;

import com.example.relevandopeligros.DisplayMessageActivity;
import com.example.relevandopeligros.R;
import com.example.relevandopeligros.R.id;
import com.example.relevandopeligros.R.layout;
import com.example.relevandopeligros.R.menu;

import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.content.Intent;
import android.hardware.Camera;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.os.Build;

public class ImagenesActivity extends ActionBarActivity {

	private static Camera mCamera = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_imagenes);
		if (savedInstanceState == null) {
			getSupportFragmentManager().beginTransaction()
					.add(R.id.container, new PlaceholderFragment()).commit();
		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.imagenes, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}

	/**
	 * A placeholder fragment containing a simple view.
	 */
	public static class PlaceholderFragment extends Fragment {

		public PlaceholderFragment() {
		}

		@Override
		public View onCreateView(LayoutInflater inflater, ViewGroup container,
				Bundle savedInstanceState) {
			View rootView = inflater.inflate(R.layout.fragment_imagenes,
					container, false);
			return rootView;
		}
	}
	
	/** Called when the user touches the button camera */
	public void openCam(View view) {
	    // Do something in response to button click
		try {
	        releaseCameraAndPreview();
	        mCamera = Camera.open();
	        
	    } catch (Exception e) {
	        Log.e(getString(R.string.app_name), "failed to open Camera");
	        e.printStackTrace();
	    }
	}
	
	private void releaseCameraAndPreview() {
	    //mPreview.setCamera(null);
	    if (mCamera != null) {
	        mCamera.release();
	        mCamera = null;
	    }
	}
	
	/** Called when the user touches the button gallery */
	public void openGallery(View view) {
	    // Do something in response to button click
		
	}
	
	/** Called when images are loaded **/
	public void toUbicacion(View view){
		//Create the intent
    	Intent intent = new Intent(this, UbicacionActivity.class);
    	
    	//Obtain EditText, and add the message to the intent
    	//EditText editText = (EditText) findViewById(R.id.edit_message);
    	//String message = editText.getText().toString();
    	//intent.putExtra(EXTRA_MESSAGE, message);
    	
    	//start the second activity
    	startActivity(intent);
	}
}
